<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="UTF-8">
<%@include file="/WEB-INF/include-head.jsp" %>
<link rel="stylesheet" href="css/pagination.css"/>
<script type="text/javascript" src="jquery/jquery.pagination.js"></script>
<script type="text/javascript" src="layer/layer.js" charset="utf-8"></script>
<script type="text/javascript">
    $(function () {
        initPagination() ;
    });
    function initPagination() {
        //获取总记录数
        var totalRecord = ${requestScope.pageInfo.total} ;
        var properties = {
            num_edge_entries: 3, //边缘页数
            num_display_entries: 5, //主体页数
            callback: pageSelectCallback,//点击翻页跳转
            items_per_page:${requestScope.pageInfo.pageSize}, //每页显示1项
            current_page:${requestScope.pageInfo.pageNum-1},
            prev_text:"上一页",
            next_text:"下一页"
        };
        $("#Pagination").pagination(totalRecord,properties);
    }

    function pageSelectCallback(pageindex, jq){
        var pageNum = pageindex +1 ;
        window.location.href = "admin/get/page.html?pageNum="+pageNum+"&keyword=${param.keyword}" ;
        return false;
    }


    $(function(){
        // [name=roleName]表示匹配name属性等于roleName的元素
        var checkBoxs = ($("#adminTbody [class=checkBox]"));



        // 给总summaryBox绑定单击响应函数
        $("#summaryBox").click(function () {
            // 获取当前多选框自身状态
            var currentStatus = this.checked;
            // 多选框的状态设置其他框
            $(".checkBox").prop("checked",currentStatus);
        });
        // 全选、全不选反向操作
        $("#adminTbody").on("click",".checkBox",function () {
            var checkedBoxCount = $(".checkBox:checked").length;
            var totalBoxCount = $(".checkBox").length ;
            // 使用二者的比较设置checkBox
            $("#summaryBox").prop("checked",checkedBoxCount == totalBoxCount) ;
        });

        // 批量删除按钮
        $("#removeAdminBtn").click(function () {
            var adminArray = [];
            $(".checkBox:checked").each(function () {
                var adminId = this.id ;
                adminArray.push(adminId);
            });
            //检查roleArray的长度是否为0
            if(adminArray.length == 0){
                layer.msg("请至少选择一个执行删除")
                return ;
            }
            console.log(adminArray)
            if(confirm("确定要删除所选项目？")){

            $.ajax({
                type:"post",
                url:"remove/AdmindIds.html",
                data:{userList: adminArray.toString()},
                success: function(){
                    layer.msg("删除成功！");
                    //延时执行
                    setTimeout(function(){
                        window.location.reload();
                    },1000);
                    // window.location.reload();
                },
                error :function(){
                    layer.msg("删除失败！")
                }
            });
            }
        })
    });
</script>
<body>
<%@include file="/WEB-INF/include-nav.jsp" %>
<div class="container-fluid">
    <div class="row">
            <%@include file="/WEB-INF/include-sidebar.jsp" %>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form action="/admin/get/page.html" method="post" class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <%
                                    String keyword = request.getParameter("keyword") ;
                                    if (keyword == null) {
                                        keyword = "" ; // 设置空字符串
                                    }
                                %>
                                <input name="keyword" id="keyword" class="form-control has-success" value="<%=keyword%>" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button type="submit" class="btn btn-warning"><i class="glyphicon glyphicon-search" onclick="wordback()"></i> 查询</button>
                    </form>
                    <button type="button" id="removeAdminBtn" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
                    <%--<button type="button" class="btn btn-primary" style="float:right;" onclick="window.location.href='add.html'"><i class="glyphicon glyphicon-plus"></i> 新增</button>--%>
                    <a href="admin/to/add/page.html" class="btn btn-primary" style="float:right;"><i class="glyphicon glyphicon-plus"></i> 新增</a>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr>
                                <th width="30">#</th>
                                <th width="30"><input id="summaryBox" type="checkbox"></th>
                                <th>账号</th>
                                <th>名称</th>
                                <th>邮箱地址</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody id="adminTbody">
                            <c:if test="${empty requestScope.pageInfo.list}">
                                <tr>
                                    <td colspan="6" align="center">抱歉！没有查询到您需要的数据！</td>
                                </tr>
                            </c:if>
                            <c:if test="${!empty requestScope.pageInfo.list}">
                                <c:forEach items="${requestScope.pageInfo.list}" var="admin" varStatus="myStatus">
                            <tr>
                                <td>${myStatus.count}</td>
                                <td><input type="checkbox" class="checkBox" id="${admin.id}"></td>
                                <td>${admin.loginAcct}</td>
                                <td>${admin.userName}</td>
                                <td>${admin.email}</td>
                                <td>
                                    <button type="button" class="btn btn-success btn-xs"><i class=" glyphicon glyphicon-check"></i></button>
                                    <a href="/admin/to/edit/page.html?adminId=${admin.id}&pageNum=${requestScope.pageInfo.pageNum}&keyword=${param.keyword}" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></a>
                                    <a href="admin/remove/${admin.id}/${requestScope.pageInfo.pageNum}/${param.keyword}.html" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></a>
                                </td>
                            </tr>
                                </c:forEach>
                            </c:if>
                            </tbody>
                            <tfoot>
                            <tr>
                                <td colspan="6" align="center">
                                    <div id="Pagination" class="pagination"><!-- 这里显示分页 --></div>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>